package sip

import (
	"encoding/xml"
)

//sip message body
//xml解析的字段
const (
	MESSAGE_CATALOG                  = "Catalog"
	MESSAGE_DEVICE_INFO              = "DeviceInfo"
	MESSAGE_RECORD_INFO              = "RecordInfo"
	MESSAGE_BROADCAST                = "Broadcast"
	MESSAGE_DEVICE_STATUS            = "DeviceStatus"
	MESSAGE_DEVICE_CTL               = "DeviceControl"
	MESSAGE_KEEP_ALIVE               = "Keepalive"
	MESSAGE_ALARM                    = "Alarm"
	MESSAGE_MOBILE_POSITION          = "MobilePosition"
	MESSAGE_MOBILE_POSITION_INTERVAL = "Interval"

	ELEMENT_DEVICE_ID   = "DeviceID"
	ELEMENT_DEVICE_LIST = "DeviceList"
	ELEMENT_NAME        = "Name"
	ELEMENT_STATUS      = "Status"
)

type QueryBody struct {
	XMLName  xml.Name
	CmdType  string
	DeviceID string
	SN       string
}

type ReponseBody struct {
	XMLName    xml.Name `xml:"Reponse"`
	CmdType    string
	DeviceID   string
	SN         string
	SumNum     uint16
	DeviceList []*ChannelInfo `xml:"DeviceList>Item"`
}

type ChannelInfo struct {
	DeviceID     string
	Name         string
	Manufacturer string
	Model        string
	Owner        string
	CivilCode    string //对应行政区域代码
	Block        string //对应组织机构代码 符合GA/T 380-2011
	Address      string //设备安装地址
	Parental     string
	ParentID     string //设备父级设备ID/虚拟组织
	SafetyWay    string
	RegisterWay  string
	Secrecy      uint
	IPAddress    string
	Port         uint16
	Status       string
	Longitude    string
	Latitude     string
}

func XmlMashal(mode interface{}) (string, error) {
	byts, err := xml.MarshalIndent(mode, "", "    ")
	if err != nil {
		return "", err
	}

	return xml.Header + "\r\n" + string(byts), nil
}
